from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-16 14:14:01.115233
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 16, Sep, 2021
Time: 14:14:05
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.1958
Nobs: 416.000 HQIC: -46.7230
Log likelihood: 4567.61 FPE: 3.62020e-21
AIC: -47.0678 Det(Omega_mle): 2.92339e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.437825 0.092841 4.716 0.000
L1.Burgenland 0.103997 0.047952 2.169 0.030
L1.Kärnten -0.114078 0.023932 -4.767 0.000
L1.Niederösterreich 0.165499 0.102738 1.611 0.107
L1.Oberösterreich 0.119806 0.100891 1.187 0.235
L1.Salzburg 0.285477 0.050341 5.671 0.000
L1.Steiermark 0.023815 0.066766 0.357 0.721
L1.Tirol 0.108669 0.052773 2.059 0.039
L1.Vorarlberg -0.109413 0.047383 -2.309 0.021
L1.Wien -0.014418 0.091790 -0.157 0.875
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.012848 0.214340 0.060 0.952
L1.Burgenland -0.049054 0.110707 -0.443 0.658
L1.Kärnten 0.037098 0.055250 0.671 0.502
L1.Niederösterreich -0.215432 0.237190 -0.908 0.364
L1.Oberösterreich 0.482427 0.232926 2.071 0.038
L1.Salzburg 0.307788 0.116222 2.648 0.008
L1.Steiermark 0.115978 0.154141 0.752 0.452
L1.Tirol 0.314876 0.121836 2.584 0.010
L1.Vorarlberg 0.003049 0.109393 0.028 0.978
L1.Wien 0.002228 0.211914 0.011 0.992
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.248003 0.047283 5.245 0.000
L1.Burgenland 0.089941 0.024422 3.683 0.000
L1.Kärnten -0.001448 0.012188 -0.119 0.905
L1.Niederösterreich 0.210228 0.052324 4.018 0.000
L1.Oberösterreich 0.169846 0.051383 3.305 0.001
L1.Salzburg 0.033970 0.025638 1.325 0.185
L1.Steiermark 0.018220 0.034003 0.536 0.592
L1.Tirol 0.065850 0.026877 2.450 0.014
L1.Vorarlberg 0.058752 0.024132 2.435 0.015
L1.Wien 0.108394 0.046748 2.319 0.020
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181477 0.046179 3.930 0.000
L1.Burgenland 0.049291 0.023851 2.067 0.039
L1.Kärnten -0.006665 0.011903 -0.560 0.576
L1.Niederösterreich 0.136584 0.051102 2.673 0.008
L1.Oberösterreich 0.316773 0.050183 6.312 0.000
L1.Salzburg 0.100821 0.025040 4.026 0.000
L1.Steiermark 0.132719 0.033209 3.996 0.000
L1.Tirol 0.075343 0.026249 2.870 0.004
L1.Vorarlberg 0.057271 0.023568 2.430 0.015
L1.Wien -0.043944 0.045656 -0.963 0.336
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.208423 0.091749 2.272 0.023
L1.Burgenland -0.051746 0.047388 -1.092 0.275
L1.Kärnten -0.034585 0.023650 -1.462 0.144
L1.Niederösterreich 0.109281 0.101529 1.076 0.282
L1.Oberösterreich 0.172973 0.099704 1.735 0.083
L1.Salzburg 0.254155 0.049749 5.109 0.000
L1.Steiermark 0.079124 0.065980 1.199 0.230
L1.Tirol 0.123826 0.052152 2.374 0.018
L1.Vorarlberg 0.115320 0.046826 2.463 0.014
L1.Wien 0.027442 0.090710 0.303 0.762
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.029165 0.071061 0.410 0.681
L1.Burgenland 0.024168 0.036703 0.658 0.510
L1.Kärnten 0.052271 0.018317 2.854 0.004
L1.Niederösterreich 0.213140 0.078637 2.710 0.007
L1.Oberösterreich 0.334344 0.077223 4.330 0.000
L1.Salzburg 0.045122 0.038532 1.171 0.242
L1.Steiermark -0.006507 0.051103 -0.127 0.899
L1.Tirol 0.113944 0.040393 2.821 0.005
L1.Vorarlberg 0.066891 0.036268 1.844 0.065
L1.Wien 0.128288 0.070257 1.826 0.068
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187310 0.087032 2.152 0.031
L1.Burgenland 0.016488 0.044952 0.367 0.714
L1.Kärnten -0.057311 0.022434 -2.555 0.011
L1.Niederösterreich -0.106352 0.096310 -1.104 0.269
L1.Oberösterreich 0.187204 0.094579 1.979 0.048
L1.Salzburg 0.032307 0.047192 0.685 0.494
L1.Steiermark 0.298950 0.062588 4.776 0.000
L1.Tirol 0.486018 0.049471 9.824 0.000
L1.Vorarlberg 0.068816 0.044419 1.549 0.121
L1.Wien -0.110573 0.086047 -1.285 0.199
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161134 0.094681 1.702 0.089
L1.Burgenland -0.010457 0.048902 -0.214 0.831
L1.Kärnten 0.061563 0.024406 2.522 0.012
L1.Niederösterreich 0.190799 0.104774 1.821 0.069
L1.Oberösterreich -0.129639 0.102890 -1.260 0.208
L1.Salzburg 0.237416 0.051339 4.624 0.000
L1.Steiermark 0.158194 0.068089 2.323 0.020
L1.Tirol 0.052262 0.053819 0.971 0.332
L1.Vorarlberg 0.125866 0.048322 2.605 0.009
L1.Wien 0.155664 0.093609 1.663 0.096
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.487205 0.051340 9.490 0.000
L1.Burgenland -0.008855 0.026517 -0.334 0.738
L1.Kärnten -0.009882 0.013234 -0.747 0.455
L1.Niederösterreich 0.204570 0.056813 3.601 0.000
L1.Oberösterreich 0.262295 0.055792 4.701 0.000
L1.Salzburg 0.021460 0.027838 0.771 0.441
L1.Steiermark -0.025069 0.036921 -0.679 0.497
L1.Tirol 0.067537 0.029183 2.314 0.021
L1.Vorarlberg 0.058760 0.026203 2.243 0.025
L1.Wien -0.054843 0.050759 -1.080 0.280
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.020932 0.076659 0.141099 0.132437 0.041167 0.073963 -0.002174 0.175699
Kärnten 0.020932 1.000000 -0.045012 0.126901 0.046663 0.069667 0.454284 -0.093558 0.091874
Niederösterreich 0.076659 -0.045012 1.000000 0.283737 0.080797 0.266112 0.022610 0.136576 0.258259
Oberösterreich 0.141099 0.126901 0.283737 1.000000 0.181290 0.285495 0.156877 0.098862 0.138839
Salzburg 0.132437 0.046663 0.080797 0.181290 1.000000 0.125867 0.054037 0.101954 0.050163
Steiermark 0.041167 0.069667 0.266112 0.285495 0.125867 1.000000 0.131300 0.088751 -0.023663
Tirol 0.073963 0.454284 0.022610 0.156877 0.054037 0.131300 1.000000 0.040274 0.114523
Vorarlberg -0.002174 -0.093558 0.136576 0.098862 0.101954 0.088751 0.040274 1.000000 -0.049520
Wien 0.175699 0.091874 0.258259 0.138839 0.050163 -0.023663 0.114523 -0.049520 1.000000